package project_model;

/**
 * PrototypeTest
 *
 * @author Syzer
 * @Description 原型模式
 * @Date 2021/7/8 15:37
 */
public class PrototypeTest {

    static class Prototype implements Cloneable {
        int age;
        PrototypeTest prototype = new PrototypeTest();

        public Prototype(int age) {
            System.out.println("原型创建成功！");
            this.age = age;
        }

        @Override
        protected Object clone() throws CloneNotSupportedException {
            System.out.println("原型复制成功！");
            return super.clone();
        }

        public PrototypeTest getPrototype() {
            return prototype;
        }
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Prototype prototype = new Prototype(123);
        Prototype clone = (Prototype) prototype.clone();
        System.out.println(clone == prototype);
        System.out.println(prototype.getPrototype() == clone.getPrototype());
    }
}
